﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataValidateAttribute
{
    class Program
    {
        static void Main(string[] args)
        {
            Demo2("鲁迅认识的那只猹", "M", -10);
            Console.ReadKey();
        }

        /// <summary>
        /// 普通方式来验证参数的方法
        /// </summary>
        /// <param name="name"></param>
        /// <param name="gender"></param>
        /// <param name="age"></param>
        static void Dome1(string name, string gender, int age)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (gender == null)
            {
                throw new ArgumentNullException("gender");
            }
            if (age <= 0)
            {
                throw new ArgumentException("age");
            }
        }

        /// <summary>
        /// 使用特性来验证参数的方法
        /// </summary>
        /// <param name="name"></param>
        /// <param name="gender"></param>
        /// <param name="age"></param>
        static void Demo2([NotNull("名字你还想空?")]string name, [NotNull]string gender, [ValidationAge("年龄错误 不能小于0")]int age)
        {
            ValidateContext.Validate(new object[] { name, gender, age });
        }
    }
}
